# import time
# from selenium import webdriver
# from selenium.webdriver.common.by import By # todo:引入By方法，做selenium定位
# bro = webdriver.Chrome() # todo：实例化driver
# # executable_path：指定driver的路径
# bro.get("https://www.baidu.com/") # todo：打开一个浏览器页面
# bro.maximize_window() # todo：浏览器放大
# time.sleep(2) # todo：强制等待2s
# bro.find_element(By.ID, "kw").send_keys("selenium")
# time.sleep(3)
# bro.find_element(By.ID, "su").click()
# time.sleep(3)


"""获取元素方式一共8种
id
aa=dirver.find_element(By.ID, "kw")
aa.send_keys("selenium")    把元素对象赋值给aa aa就是元素对象本身 通过aa去做动作

dirver.find_element(By.ID, "kw").send_keys("selenium")  直接获取元素做动作

bb=dirver.find_elements(By.ID, "kw").click()    查找多个同名元素，bb就是一个列表，里面是一个个元素对象

dirver.find_element_by_id("kw")   这个获取方式被淘汰了

class
dirver.find_element(By.CLASS_NAME, "kw")
dirver.find_elements(By.CLASS_NAME, "kw")

name
dirver.find_element(By.NAME, "kw")
dirver.find_elements(By.NAME, "kw")

tag_name
bb=dirver.find_elements(By.TAG_NAME, "su")

link_text

partial link text

xpath
dirver.find_element(By.XPATH, "/html/body/div/div[2]/div[5]/div[1]/div/form/span[1]/input").click()

css

"""




#通过遍历元素的列表，挨个查看元素的text文本信息，来做判断，哪个是我需要的
#也可以通过索引的方式直接去使用，但是可能会有时候，数量过于庞大，不好判断具体索引，所以用上述这种来判断


# driver.get("https://www.hao123.com/?src=from_pc")
# time.sleep(2)
# ff=driver.find_elements(By.CLASS_NAME,"channel-link")
# for i in ff:
#     if i.text=="国创":
#         i.click()
#通过遍历元素的列表，挨个查看元素的text文本信息，来做判断，哪个是我需要的
#也可以通过索引的方式直接去使用，但是可能会有时候，数量过于庞大，不好判断具体索引，所以用上述这种来判断
# ff=driver.find_elements(By.CLASS_NAME,"g-gc")
# for i in ff:
#     if i.get_attribute("href")=="http://www.people.com.cn/":
#         print(i)
#         i.click()
# #同名特征之下，通过一些，特殊的特征，去查找我想要的元素   i.get_attribute("特征的键")=="特征的值"
#
#
# aa=driver.window_handles   获取当前句柄
# driver.switch_to.window(aa[-1])  切换句柄

# 键盘操作
# key()类
# from selenium.webdriver.common.keys import Keys
# driver.get('https://www.baidu.com/')
# driver.find_element(By.ID, 'kw').send_keys('python')
# sleep(1)
# driver.find_element(By.ID, 'kw').send_keys(Keys.BACK_SPACE)
# # BACK_SPACE 删除结尾单个字节
# sleep(1)
# driver.find_element(By.ID, 'kw').send_keys(Keys.SPACE)
# # 空格
# sleep(1)
# driver.find_element(By.ID, 'kw').send_keys(Keys.ENTER)
# # 点击电脑上的确认回车键
# sleep(1)
# driver.find_element(By.ID, 'kw').send_keys(Keys.CONTROL, 'a')
# # 键盘按住ctrl+a
# sleep(1)
# driver.find_element(By.ID, 'kw').send_keys(Keys.CONTROL, 'x')
# # 键盘按住ctrl+x
# sleep(1)
# driver.find_element(By.ID, 'kw').send_keys(Keys.CONTROL, 'v')
# # 键盘按住ctrl+v
# sleep(1)
# driver.find_element(By.ID, 'kw').clear()
# # 清除


"""首先要倒包，将鼠标移动的功能ActionChains类倒进来
from selenium.webdriver.common.action_chains import ActionChains

driver.get('http://www.baidu.com')
# 将【设置】按钮元素付给set1
set1 = driver.find_element(By.ID, 's-usersetting-top')
# 把鼠标移动到设置上面
ActionChains(driver).move_to_element(set1).perform()
sleep(2)
driver.find_element(By.XPATH, '//span[@class="set" and text()="搜索设置"]').click()
# 过两秒后我在点击’搜索设置‘
sleep(2)
driver.find_element(By.XPATH, '//*[@id="se-setting-7"]/a[2]').click()
# 点击保存设置
sleep(2)
driver.switch_to.alert.accept()
# 点击弹窗的确定
sleep(2)"""






# import time
#
#
# # 终端命令
# # command = 'cmd /c start cmd.exe /K chrome --remote-debugging-port=9222'
# # chrome --remote-debugging-port=9222
# # subprocess.run(command, shell=True)
#
# from selenium import webdriver
# from selenium.webdriver.chrome.options import Options
# from selenium.webdriver.common.by import By # todo:引入By方法，做selenium定位
#
# options = Options()
# options.debugger_address = '127.0.0.1:9222'
# driver = webdriver.Chrome(options=options)
#
# driver.get('https://www.bilibili.com')
# time.sleep(2)
# driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div[1]/div[1]/div/div/form/div[1]/input')\
#     .send_keys('炸雷')
# driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div[1]/div[1]/div/div/form/div[2]').click()
# # 获取句柄
# aa=driver.window_handles
# driver.switch_to.window(aa[-1])
# time.sleep(1)
#
# driver.find_element(By.XPATH,'/html/body/div[3]/div/div[2]/div[2]/div/div/div/div[2]/div/div[1]/div/div[2]/a/div/div[1]/picture/img').click()
# aa=driver.window_handles
# driver.switch_to.window(aa[-1])
# time.sleep(1)
# driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/div[1]/div[3]/div[1]/div/div[1]/div').click()





# driver.get("https://mail.126.com/")
# time.sleep(3)
#
# aa=driver.find_elements(By.TAG_NAME,"iframe")#通过tag_name找到ifram层级
#
# driver.switch_to.frame(aa[0])#进入一层iframe层级
# time.sleep(3)
# driver.find_element(By.NAME,"email").send_keys("15542279447")
# driver.switch_to.parent_frame()#跳出一层iframe层级
#
# driver.switch_to.default_content()#跳出所有iframe层级

import time

# 终端命令
# chrome --remote-debugging-port=9222
# subprocess.run(command, shell=True)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By # todo:引入By方法，做selenium定位

options = Options()
options.debugger_address = '127.0.0.1:9222'
driver = webdriver.Chrome(options=options)
driver.get('https://mail.163.com/')
time.sleep(2)
aa=driver.find_elements(By.CLASS_NAME,"oz0")
aa[1].click()
# for i in aa:
#     if i.text=="写 信":
#         i.click()
# driver.find_elements(By.CLASS_NAME,"nui-editableAddr-txt").send_keys("qinzhicheng0633@163.com")
driver.find_element(By.CLASS_NAME,'nui-editableAddr-ipt').send_keys("qinzhicheng0633@163.com")
# time.sleep(2)
driver.find_element(By.XPATH,"/html/body/div[2]/div[1]/div[2]/div[1]/section/header/div[2]/div[1]/div/div/input").send_keys("1130")
# time.sleep(2)
driver.find_elements(By.CLASS_NAME,'nui-btn-text')[2].click()


"""下拉栏

from selenium.webdriver.support.select import Select

aa=driver.find_element(By.ID,"s1")
bb=Select(aa)
# bb.select_by_index(3)
# bb.select_by_value("49")
# bb.select_by_visible_text("Fax")
"""

